package com.caow.androidcomposebase

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.alibaba.android.arouter.facade.annotation.Route
import com.caow.androidcomposebase.router.ROUTER_MAIN
import com.caow.androidcomposebase.ui.theme.AndroidComposeBaseTheme
import com.caow.composebase.BaseActivity

@Route(path = ROUTER_MAIN)
class MainActivity : BaseActivity<MainViewModel>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val number = viewModel.clickNumber.collectAsState()
            AndroidComposeBaseTheme {
                Box(modifier = Modifier.fillMaxSize()) {
                    Greeting(
                        number.value,
                        Modifier
                            .align(Alignment.Center)
                            .clickable { viewModel.onClick() })
                }
            }
        }
    }
}

@Composable
fun Greeting(number: Int, modifier: Modifier = Modifier) {
    Text(
        text = "Hello World! click number $number",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    AndroidComposeBaseTheme {
        Greeting(0)
    }
}